﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

/// <summary>
/// TDateTime 的摘要说明
/// </summary>
public class TDateTime
{
    public string[] plantimes2 = new string[] { "07:00", "07:15", "07:30", "07:45", "08:00", "08:15", "08:30", "08:45", "09:00", "09:15", "09:30", "09:45", "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00", "19:15", "19:30", "19:45", "20:00", "20:15", "20:30", "20:45", "21:00", "21:15", "21:30", "21:45", "22:00", "22:15", "22:30", "22:45", "23:00"};
    public static string[] plantimes1 = new string[] { "09:00", "09:15", "09:30", "09:45", "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00" };
    public static string[] plantimes = new string[] { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"};

    public TDateTime()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public static int GetWeekNum(DateTime cdate)
    {
        System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
        int weekOfYear = gc.GetWeekOfYear(cdate, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
        return weekOfYear;
    }

    //星期日是零,周一至六为1-6
    public static DateTime GetBDateOfWeek(DateTime cdate)
    {
        while (System.Convert.ToInt16(cdate.DayOfWeek)!=1)
        {
            cdate = cdate.AddDays(-1);
        }
        return cdate;
    }

    public static DateTime GetEDateOfWeek(DateTime cdate)
    {
        while (System.Convert.ToInt16(cdate.DayOfWeek)!=0)
        {
            cdate = cdate.AddDays(1);
        }
        return cdate;
    }

    public static string GetWeekName(int weeknum)
    {
        string result = "";

        switch (weeknum)
        {
            case 1:
                result = "星期一";
                break;
            case 2:
                result = "星期二";
                break;
            case 3:
                result = "星期三";
                break;
            case 4:
                result = "星期四";
                break;
            case 5:
                result = "星期五";
                break;
            case 6:
                result = "星期六";
                break;
            case 0:
                result = "星期日";
                break;
        };

        return result;
    }

    public static string GetWeekName(string week)
    {
        string result = "";

        switch (week)
        {
            case "Monday":
                result = "周一";
                break;
            case "Tuesday":
                result = "周二";
                break;
            case "Wednesday":
                result = "周三";
                break;
            case "Thursday":
                result = "周四";
                break;
            case "Friday":
                result = "周五";
                break;
            case "Saturday":
                result = "周六";
                break;
            case "Sunday":
                result = "周日";
                break;
        };

        return result;
    }

    public static string GetWeekName2(string week)
    {
        string result = "";

        switch (week)
        {
            case "Monday":
                result = "星期一";
                break;
            case "Tuesday":
                result = "星期二";
                break;
            case "Wednesday":
                result = "星期三";
                break;
            case "Thursday":
                result = "星期四";
                break;
            case "Friday":
                result = "星期五";
                break;
            case "Saturday":
                result = "星期六";
                break;
            case "Sunday":
                result = "星期日";
                break;
        };

        return result;
    }

    public static string GetPlans(string inman, DateTime plandate, string plantime, int plantimenum)
    {
        string result = "";

        string sSql = "select plancontent,planmans,status,uid from t_plan where inman='" + inman + "' and plandate='" + plandate.ToString("yyyy-MM-dd") + "' and plantime='" + plantime + "' and plantimenum=" + plantimenum.ToString() + " order by iid";
        TSqlDBReader oReader = new TSqlDBReader(sSql);
        while (oReader.FDataReader.Read())
        {
            int iflag = oReader.FDataReader.GetInt16(2);
            switch (iflag)
            {
                case 0:
                    result += "<div>·<span onclick=\"GetEvent('" + oReader.FDataReader.GetValue(3).ToString() + "','" + plandate.ToString("yy-MM-dd") + "','" + plantime + "','" + plantimenum.ToString() + "','" + oReader.FDataReader.GetValue(0).ToString() + "','" + oReader.FDataReader.GetValue(1).ToString() + "')\" style=\"cursor: hand;\">";
                    result += oReader.FDataReader.GetValue(0).ToString();
                    if (oReader.FDataReader.GetValue(1).ToString() != "")
                    {
                        result += "(" + oReader.FDataReader.GetValue(1).ToString() + ")";
                    }
                    result += "</span></div>";
                    break;
                case 1:
                    result += "<div>·<span style=\"text-decoration: line-through; color: gray;\">";
                    result += oReader.FDataReader.GetValue(0).ToString();
                    if (oReader.FDataReader.GetValue(1).ToString() != "")
                    {
                        result += "(" + oReader.FDataReader.GetValue(1).ToString() + ")";
                    }
                    result += "</span></div>";
                    break;
            }
        }
        oReader.Free();

        if (result == "")
        {
            result = "&nbsp;";
        }

        return result;
    }
}
